package com.wxhntmy.redis;

import com.wxhntmy.config.ProjectConfig;
import com.wxhntmy.config.RedisConfig;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import redis.clients.jedis.JedisPooled;

/**
 * @author chenwc
 * @package com.wxhntmy.redis
 * @project GoogleTranslate
 * @date 2025/6/24
 */
public class JedisTool {
    private static final RedisConfig REDIS_CONFIG = ProjectConfig.getInstance().getRedis();
    private static JedisPooled jedis;

    public static JedisPooled getJedis() {
        if (jedis == null) {
            jedis = new JedisPooled(new GenericObjectPoolConfig<>(), REDIS_CONFIG.getHost(),
                    REDIS_CONFIG.getPort(),
                    REDIS_CONFIG.getTimeout(),
                    REDIS_CONFIG.getPassword());
        }
        return jedis;
    }

    public static void close() {
        if (jedis != null) {
            jedis.close();
        }
    }
}
